#!/usr/bin/env python

#
#    Copyright (c) 2009 Corey Goldberg (corey@goldb.org)
#    License: GNU GPLv3
#
#    This file is part of PerfMetrics.
#    
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.  See the GNU General Public License 
#    for more details.
#


host = '127.0.0.1'
username = ''
password = ''


import sys

try:
    import pythoncom
except ImportError:
    print 'Python Windows extensions are missing. you must install this package.'
    sys.exit()
    
try:
    import lib.wmi as wmi
except ImportError:
    print 'WMI module missing.  wmi.py must be present.'
    sys.exit()

print 'making WMI connection to %s...' % host

try:
    c = wmi.WMI(computer=host, user=username, password=password)    
    print 'success.'
except Exception, e:
    print 'connection failed:\n%s.' % str(e)    
    sys.exit() 
    
print 'running WQL query...'

try:
    num_cpus = len([cpu for cpu in c.Win32_Processor()])
    print 'success.'
except Exception, e:
    print 'query failed:\n%s.' % str(e)
    sys.exit()    

print 'WMI/WQL is working. detected %i cpu/core(s) on %s.' % (num_cpus, host)
print 'done.'
